package com.shiliao.app.activity.index.presenter;

import android.text.TextUtils;

import com.shiliao.app.activity.index.entity.WaitExamineEntity;
import com.shiliao.app.activity.index.service.IWaitExamineService;
import com.shiliao.app.activity.index.service.impl.WaitExamineImpl;
import com.shiliao.app.activity.index.view.WaitExamineView;
import com.shiliao.app.utils.YMServerUtil;
import com.yimei.framework.mvp.presenter.IBasePresenter;
import com.yimei.framework.network.ICallBack;
import com.yimei.framework.util.LogUtil;
import com.yimei.framework.util.ParseHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yinzhiqiang on 2018/4/20.
 */

public class WaitExaminePresenter extends IBasePresenter<IWaitExamineService>{
    private IWaitExamineService waitExamineService;
    private WaitExamineView waitExamineView;
    private String statusList;
    public WaitExaminePresenter(WaitExamineView view) {
        waitExamineView = view;
        waitExamineService=new WaitExamineImpl();
        setService(waitExamineService);
    }

    public void requestExamineList(String userId) {
        Map map = new HashMap();

        if (!TextUtils.isEmpty(userId)) {
            map.put("user_id", userId);
            waitExamineService.requestExamineList(YMServerUtil.ACTION_GET_TODAYAUDIT, map, new ICallBack() {
                @Override
                public void onSuccess(int statusCode, Object result) {
                  List<WaitExamineEntity> list= ParseHelper.getModelList(result.toString(),
                          "content_array", WaitExamineEntity.class);
                  waitExamineView.setAdapter(list);
                  waitExamineView.updateView();
                  boolean show=false;
                  for (int i=0;i<list.size();i++){
                     statusList=  list.get(i).status;
                      if (statusList.equals("0")){
                          show=false;
                          break;
                      }
                      show=true;
                  }
                    if (show){
                        waitExamineView.toast();
                    }
                }

                @Override
                public void onFail(int statusCode, Object result) {

                }
            });
        }
    }
}
